package math

import "jvmgo/ch06/instructions/base"
import "jvmgo/ch06/rtda"

// double相加指令
type DADD struct {
    base.NoOperandsInstruction
}

func (self *DADD) Execute(frame *rtda.Frame) {
    stack := frame.OperandStack()
    v1 := stack.PopDouble()
    v2 := stack.PopDouble()
    result := v1 + v2
    stack.PushDouble(result)
}

// float相加指令
type FADD struct {
    base.NoOperandsInstruction
}

func (self *FADD) Execute(frame *rtda.Frame) {
    stack := frame.OperandStack()
    v2 := stack.PopFloat()
    v1 := stack.PopFloat()
    result := v1 + v2
    stack.PushFloat(result)
}

// int相加指令
type IADD struct {
    base.NoOperandsInstruction
}

func (self *IADD) Execute(frame *rtda.Frame) {
    stack := frame.OperandStack()
    v2 := stack.PopInt()
    v1 := stack.PopInt()
    result := v1 + v2
    stack.PushInt(result)
}

// long相加指令
type LADD struct {
    base.NoOperandsInstruction
}

func (self *LADD) Execute(frame *rtda.Frame) {
    stack := frame.OperandStack()
    v2 := stack.PopLong()
    v1 := stack.PopLong()
    result := v1 + v2
    stack.PushLong(result)
}
